<?php
/*
 * 调用Yii的函数文件
 */

if(!defined('IN_SUPESITE')) {
	exit('Access Denied');
}
include_once(S_ROOT.'./class/MyApc.class.php');

//test
function test()
{
	
	$modelClass = 'app\com\simtoon\models\testModel';
	$_POST['id'] = 8;
	$data = YiiComm::findData($modelClass, $_POST);
// 	print_r($data);

// 	$pagin = $data->getPagination();
// 	$pagin = objectToArray($pagin);
// 	print_r($pagin);

	
// 	$class = new ReflectionClass($modelClass);
// 	print_r($class);
// 	print_r("++++++++++++++++++  class");
// 	echo '</br>';
	
// 	$ins = $class->newInstance();
// 	print_r($ins);
// 	print_r("++++++++++++++++++   instance");
// 	echo '</br>';
	
// 	$ge=$class->getMethod('sum');
// 	print_r($ge);
// 	print_r("++++++++++++++++++  method");
// 	echo '</br>';
	
// 		$rs = $ge->invokeArgs($ins,array());
		
// 		print_r("+++++++invokeArgs++++++++++  method");
// 		echo '</br>';
	
// 	print_r($rs);
// 	echo '</br>';
}

/**
 * 获取最新出租的二手房
 * @return Ambigous <multitype:, mixed>
 * by  yangliang
 */
function getRentnewhouse()
{
    $apc = new MyApc();
    foreach($_POST as $key=>$val){
        $arr[] = $key.'_'.$val;
    }
    $str =implode('_',$arr);

    $_POST['type'] = 101;

//    if($apc->exists($str.'_'.$_POST['type'])){
//        $Rentnewhouse = $apc->get_cache($str.'_'.$_POST['type']);
//    }else{
	    $modelClass = 'app\com\simtoon\models\SecNewHouse';

        $Rentnewhouse = YiiComm::findData($modelClass, $_POST);
//        $apc->set_cache($str.'_'.$_POST['type'],$Rentnewhouse);
//    }
    return $Rentnewhouse;
}



/**
 * 获取最新出售的二手房
 * @return Ambigous <multitype:, mixed>
 * by  yangliang
 */
function getSalenewhouse()
{
    $apc = new MyApc();
    foreach($_POST as $key=>$val){
        $arr[] = $key.'_'.$val;
    }
    $str =implode('_',$arr);

    $_POST['type'] = 100;
//    if($apc->exists($str.'_'.$_POST['type'])){
//        $data = $apc->get_cache($str.'_'.$_POST['type']);
//    }else {
        $modelClass = 'app\com\simtoon\models\SecNewHouse';

        $data = YiiComm::findData($modelClass, $_POST);
//        $apc->set_cache($str.'_'.$_POST['type'],$data);
//    }
	return $data;
}



//获取wap 首页最新热推房源
function getWapSalenewhouse()
{
    $apc = new MyApc();
    foreach($_POST as $key=>$val){
        $arr[] = $key.'_'.$val;
    }
    $str =implode('_',$arr);

    $_POST['type'] = 100;
//    if($apc->exists($str.'_'.$_POST['type'])){
//        $data = $apc->get_cache($str.'_'.$_POST['type']);
//    }else {
    $modelClass = 'app\com\simtoon\models\SecNewHouse';

    $data = YiiComm::executeByMethod($modelClass,'getWaphouse', $_POST,false);
    $data = $data->getModels();

//        $apc->set_cache($str.'_'.$_POST['type'],$data);
//    }
    return $data;
}
/**查询首页二手房市场趋势中新增的二手房
 * @return array
 */
function getNewhouse()
{

    $apc = new MyApc();
    foreach($_POST as $key=>$val){
        $arr[] = $key.'_'.$val;
    }
    $str =implode('_',$arr);

    $_POST['type'] = 100;
    if($apc->exists($str.'_'.$_POST['type'])){
        $data = $apc->get_cache($str.'_'.$_POST['type']);
    }else {
        $modelClass = 'app\com\simtoon\models\SecNewHouse';
        $data = YiiComm::executeByMethod($modelClass, 'getNewhouse', $_POST);
        $data = $data->getModels();
        $apc->set_cache($str.'_'.$_POST['type'],$data);
    }
    return $data;
}


/**
 * 2015-08-24 add by hetao: 统计在售二手房套数
 * @return array
 */
function houseCount()
{
    $apc = new MyApc();
    if($apc->exists('houseCount')){
        $count = $apc->get_cache('houseCount');
    }else {
    $modelClass = 'app\com\simtoon\models\SecNewHouse';
    $data = YiiComm::executeByMethod($modelClass, 'houseCount', $_POST);
    $data = $data->getModels();
    $count = $data[0]['count'];
    $apc->set_cache('houseCount',$count);
   }
    return $count;
}


/**
 * 2015-08-248 add by hetao: 首页趋势图统计
 * @return array
 */
function echartCount()
{
    $apc = new MyApc();
    if($apc->exists('pre_echartCount')){
        $res = $apc->get_cache('pre_echartCount');
    }else {
        $modelClass = 'app\com\simtoon\models\Statistics';
        $data = YiiComm::executeByMethod($modelClass, 'echatCount', $_POST, false);
        $data = $data->getModels();
        $res = json_encode($data);
        $apc->set_cache('pre_echartCount',$res);
    }
    return $res;
}
/**
 * 根据搜索条件查询房源
 * @param unknown $_SGET
 * @return Ambigous <multitype:, mixed>
 * by yangliang
 */
function SearchHouse($_SGET){
	$modelClass = 'app\com\simtoon\models\SearchHouse';
    $data =  YiiComm::findDataByPagination($modelClass, $_SGET);
    $pagin = $data->getPagination();
    $pagin = objectToArray($pagin);
    $apiresult = $data->getModels();


	return $apiresult;
}

function getDomainName($keywords){
    //clear_cache();
    if(!empty($keywords) ){
        $modelClass = 'app\com\simtoon\models\SmallCode';
        $domainResult =  get_domainName_cache_value('domain_',$keywords);
       ;
        return $domainResult;
    }


}

/**
 * 获取区域（若缓存中无区域数据则进行查询并将区域数据加入缓存）
 * @return mixed
 * 	by yangliang
 */
function getTown(){
		$modelClass = 'app\com\simtoon\models\SmallCode';
    $smallcode =  get_area_cache_value('parea_',8);
	//$smallcode = YiiComm::findData($modelClass, $_POST);
	return $smallcode;
}

//2016 03 09 获取城区信息

function getareas(){
    $modelClass='app\com\simtoon\models\SmallCode';
    $_POST['id']=3;
    $areas=get_area_cache_value('areas_',3);
    return $areas;
}




/**
 * 查询楼盘名称 （若缓存中无楼盘数据则进行查询并加入缓存）
 * @param unknown $_SGET
 * @return Ambigous <mixed, multitype:>
 * by  yangliang
 */
function getBuildArea($_SGET){
	$id = $_SGET['a'];
	
		$modelClass = 'app\com\simtoon\models\SmallCode';
		$_POST['id'] = $_SGET['a'];
    $AreaResult =  get_area_cache_value('parea_',$_POST['id']);
		//$AreaResult = YiiComm::findData($modelClass, $_POST);
   // $AreaResult = json_decode($AreaResult);
	return $AreaResult;
}

/**
 * 查询门店名称
 * @param unknown $_SGET
 * @return Ambigous <multitype:, mixed>
 */
function getdeptName($_SGET){
	$id = $_SGET['a'];

	$modelClass = 'app\com\simtoon\models\SmallCode';
	$_POST['id'] = $_SGET['a'];
	$deptResult = YiiComm::findDataByMethod($modelClass, 'getDeptName', $_POST);

	return $deptResult;
}


/**
 * 查询经纪人未评论的相关房源
 * @param unknown $_SGET
 * @return unknown
 * by yangliang
 */
function getAgentHouse($_SGET){
	$modelClass = 'app\com\simtoon\models\AgentHouse';
	$data = YiiComm::findDataByPagination($modelClass, $_SGET);
	$pagin = $data->getPagination();
	$pagin = objectToArray($pagin);
	//房源数据调用
	$AgentHouseResult = $data->getModels();
	return $AgentHouseResult;
}




/**
 * 存储经纪人发布房源评论
 * @param unknown $_SGET
 * @return Ambigous <multitype:, mixed>
 * by yangliang
 */
function setComment($_SGET){
	$modelClass = 'app\com\simtoon\models\AgentHouse';
	$rows = YiiComm::executeData($modelClass, $_SGET);
	return $rows;
}

/**
 * 存储经纪人发布其他房源评论
 * @param unknown $_SGET
 * @return Ambigous <multitype:, mixed>
 * by yangliang
 */
function setOtherComment($_SGET){
	$modelClass = 'app\com\simtoon\models\OtherHouse';
	$rows = YiiComm::executeData($modelClass, $_SGET);
	return $rows;
}
/**
 * 获取经纪人相关的房源评论
 * @param unknown $_SGET
 * @return unknown
 *  	by  yangliang
 */
function getRoleHouse($_SGET){
	$modelClass = 'app\com\simtoon\models\Comment';
	$data = YiiComm::findDataByPagination($modelClass, $_SGET);
	$pagin = $data->getPagination();
	
	$pagin = objectToArray($pagin);
	$roleHouseResult = $data->getModels();
	return $roleHouseResult;
}

/**
 * 修改经纪人的房源评论
 * @param unknown $_SGET
 * @return mixed
 */
function updateRoleHouse($_SGET){
	$modelClass = 'app\com\simtoon\models\Comment';
	$rows = YiiComm::executeByMethod($modelClass, "updateData", $_SGET);
	return $rows;
}

/**
 * 删除经纪人相关的房源评论
 * @param unknown $_SGET
 * @return mixed
 */
function deleteRoleHouse($_SGET){
	$modelClass = 'app\com\simtoon\models\Comment';
	$rows = YiiComm::executeByMethod($modelClass, "deleteData", $_SGET);
	return $rows;
}

/**
 * 更新房源评论审核状态
 * @param unknown $_SGET
 * @return mixed
 */
function updateAudit($_SGET){
	$modelClass = 'app\com\simtoon\models\Audit';
	$rows = YiiComm::executeByMethod($modelClass, "update1", $_SGET);
	return $rows;
}

/**
 * 修改自我评价
 * @param unknown $_SGET
 * @return mixed
 */
function updateAgentInfo($_SGET){
	$modelClass = 'app\com\simtoon\models\AgentInfo';
	$rows = YiiComm::executeByMethod($modelClass, "updateAgentInfo", $_SGET);
	return $rows;
}


/**
 * 修改我的行程
 * @param unknown $_SGET
 * @return mixed
 */
function updateMyTrips($_SGET){
	$modelClass = 'app\com\simtoon\models\AgentInfo';
	$rows = YiiComm::executeByMethod($modelClass, "updateMyTrips", $_SGET);
	return $rows;
}

/**
 * 设置经纪人个人信息中的熟悉商圈
 * @param unknown $_SGET
 * @return mixed
 */
function setSpecial($_SGET){
	$modelClass = 'app\com\simtoon\models\AgentInfo';
	$rows = YiiComm::executeByMethod($modelClass, "addSpecial", $_SGET);
	return $rows;
}


/**
 * 查询经纪人个人信息中的熟悉商圈
 * @param unknown $_SGET
 * @return mixed
 */
function getSpacial($_SGET){
	$modelClass = 'app\com\simtoon\models\AgentInfo';
	if(!empty($_SGET['id'])){
		$_POST['uid'] = $_SGET['id'];
	}else{
		$_POST['uid'] = $_SGET['uid'];
	}
	$spaResult = YiiComm::findData($modelClass, $_POST);
	return $spaResult;
}


/**
 * 删除经纪人熟悉的的商圈
 * @param unknown $_SGET
 * @return mixed
 */
function deleteSpecial($_SGET){
	$modelClass = 'app\com\simtoon\models\AgentInfo';
	$rows = YiiComm::executeByMethod($modelClass, "deleteSpecial", $_SGET);
	return $rows;
}


function getAgentInfo($_SGET){


	$modelClass = 'app\com\simtoon\models\JingJiRenDetail';
	$AgentResult = YiiComm::findData($modelClass, $_SGET);
	
	return $AgentResult;
}


/**
 * 添加友情店铺
 * @param unknown $_SGET
 * @return mixed
 */
function addfriend($_SGET){
	$modelClass = 'app\com\simtoon\models\FriendShop';
	$rows = YiiComm::executeByMethod($modelClass, "addFriend", $_SGET);
	return $rows;
}

/**
 * 获取友情店铺
 * @param unknown $_SGET
 * @return Ambigous <multitype:, mixed>
 */
function getFriend($_SGET){
	$modelClass = 'app\com\simtoon\models\FriendShop';
	$linksResult = YiiComm::findData($modelClass, $_SGET);
	return $linksResult;
}

/**
 * 移除友情店铺
 * @param unknown $_SGET
 * @return mixed
 */
function removeFriend($_SGET){
	$modelClass = 'app\com\simtoon\models\FriendShop';
	$rows = YiiComm::executeByMethod($modelClass, "deleteFriend", $_SGET);
	return $rows;
}

/**
 * 设置店铺房源热推状态
 * @param unknown $_SGET
 * @return mixed
 */
function updateHot($_SGET){
	$modelClass = 'app\com\simtoon\models\AgentStore';
	$rows = YiiComm::executeByMethod($modelClass, "updateHot", $_SGET);
	return $rows;
}


/**
 * 获取经纪人的有效客户
 * by  yangliang
 */
function getCustomer($_SGET){
	$modelClass = 'app\com\simtoon\models\Customer';
	$data = YiiComm::findDataByPagination($modelClass, $_SGET);
	$pagin = $data->getPagination();

	$pagin = objectToArray($pagin);
	$CustomerResult = $data->getModels();
	return $CustomerResult;
}

/**
 * 2015-11-07 add by hetao
 * 根据经纪人工号查询经纪人信息
 * @param $job_no
 * @return array
 */
function getAgentInfoByJobNo($job_no)
{

    $no = substr($job_no,0,2).'-'.substr($job_no,2,strlen($job_no));
    $arr = array('job_no'=>$no);

    $modelClass = 'app\com\simtoon\models\JingJiRenDetail';
    $AgentResult = YiiComm::findDataByMethod($modelClass,'getAgentInfoByJobNo',$arr);
    if(count($AgentResult) === 1){
        return $AgentResult[0];
    }else{
        return array();
    }

}
?>